﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using TaobaoDistrSales.Common;
using TaobaoDistrSales.Model;
using System.Diagnostics;

namespace TaobaoDistrSales
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {  
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Process[] allProcesses = Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName);
            if (allProcesses.Length > 1)
            {
                if (MessageBox.Show("该分销平台已经在运行了，需要关闭才能重新运行！\n 您确认要关闭吗？", "", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    Process currentProcess = Process.GetCurrentProcess();
                    foreach (Process p in allProcesses)
                    {
                        if (p.Id != currentProcess.Id)
                        {
                            try
                            {
                                p.Kill();
                            }
                            catch { }
                        }
                    }
                }
                else
                {
                    return;
                }
            } 
            Application.Run(new MainForm()); 
        }
    }
}
